using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using NHibernate.Expression;
using Adge.Models;
using Adge.BLL;
using Adge.Common;
using Adge.UI.WebControls;
using System.Collections.Generic;
using Adge.Common.Collections;

namespace Adge.Web.UI
{
    public partial class window : AdgePageBase
    {
        private string ObjCatname
        {
            get
            {
                string catname = string.Empty;

                if (!string.IsNullOrEmpty(Request["catname"]))
                {
                    catname = Request["catname"];
                }

                return catname;
            }
        }


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitNav();                
            }
        }

        protected void InitNav()
        {
            string catname = AdgeConfig.GetCatNameByIndex(ObjCatname).Name;
            //lblCatame.Text = catname;
            AdgeArBase<CategoryInfo> bllSub = new AdgeArBase<CategoryInfo>();
            Order[] orders = new Order[] { };
            ICriterion[] parentCriterias = new ICriterion[] { new EqExpression("Catname", catname) };//, new EqExpression("Visible", true)
            CategoryInfo[] parentSub = bllSub.SlicedFindAll(0, 100, orders, parentCriterias);
            IList<CategoryInfo> subs = new List<CategoryInfo>();
            if (parentSub.Length > 0 && parentSub[0].Children.Count > 0)
            {
                foreach (CategoryInfo var in parentSub[0].Children)
                {
                    if (var.Visible == true)
                    {
                        subs.Add(var);
                    }
                }
                //subs = parentSub[0].Children;
            }
            else
            {
                subs = Adapters.ArrayToList<CategoryInfo>(parentSub);
            }
            list.DataSource = subs;
            list.DataBind();
            CategoryLevel1.DataSource = subs;
            CategoryLevel1.DataBind();
        }        

        protected IList GetGlobalCategory(int ParentID)
        {
            AttachmentInfo[] entities;            
            AdgeArBase<CategoryInfo> bllCat = new AdgeArBase<CategoryInfo>();
            CategoryInfo cat = bllCat.GetEntityById(ParentID);
            if (null != cat)
            {
                AdgeArBase<AttachmentInfo> catlist = new Adge.BLL.AdgeArBase<AttachmentInfo>();

                ICriterion[] criterias = new ICriterion[] { new EqExpression("AdgeInfoCategory", cat) };
                Order[] orders = new Order[] { Order.Asc("AttOrder") };
                entities = catlist.SlicedFindAll(0, 5, orders, criterias);
                return entities;
            }
            return new AttachmentInfo[] { };
        }
    }
}
